import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.Image;

public class SuperMan extends Character{
	public int iStep =4;
	public int iSpr=0;
	public int iPower=3;
	public int iNumBom=3;
	public int iImageSpeed=0;
	//public int iCurrentBomb=0;
	public int iMove=-1;	
	public int m_iScore = 0;
	public static int s_iLife=3;
	//public int[] m_abBombkind = { 1200, 1400, 1600, 1800, 2000, 900, -1, 0, 0, 0, 0, 0};	
	public SuperMan(int Blood, int x_character, int y_character, Image image, int FrameW, int FrameH , int[] sequence, int dir)
	{
		super(Blood,x_character,y_character,image, FrameW, FrameH ,sequence,  dir);
		m_iUndeadTime = 3000;
	}
	public SuperMan(Sprite spr)
	{
		super(spr);	
		m_iUndeadTime = 3000;
	}
	public SuperMan(SuperMan sbm)
	{
		super(sbm);
		m_iUndeadTime = 3000;
	}
	public SuperMan(Sprite spr, int XInMap, int YInMap)
	{
		super(spr, XInMap, YInMap);
		m_iUndeadTime = 3000;
	}
	
	
	// Method for super_man
	public int PutBomb(int[][] data, TiledLayer tl)
	{
		if(iNumBom ==0)
		
		{   
			System.out.println("So bom dat bi gioi han !");
	        return 0;
		}
		if((data[iInMapY][iInMapX] == FREE_CELL) && (m_abBombkind[iCurrentBomb+6] !=0))
			{
			data[iInMapY][iInMapX] = m_abBombkind[iCurrentBomb];
			iNumBom--;
			m_abBombkind[iCurrentBomb+6]-=1;
			tl.setCell(iInMapX, iInMapY,iCurrentBomb+13);
			//play sound
			//#if USE_DEBUG
			db("Dat bom tai vi tri :"+iInMapY+":"+iInMapX + " = "+m_abBombkind[iCurrentBomb]);
			//#endif
			return 1;
			}
			else 
			{
			db("Cho nay khong dat bom dc hoac ban da het bom");	
			return 0;
			}			
	}
	public void ChangeBoom()
	{
		if(++iCurrentBomb>1)
			iCurrentBomb=0;
	}
	
public void EatItem(int[][] data)
	{
	boolean hasEat=false;
	//6 Power
	//7 life
	//8 helth
	// 9 10 11: add number of boom kind
		//System.out.println("EatItem");
		switch(data[iInMapY][iInMapX])
		{
			case 107: 
				iPower++;
				hasEat=true;
				System.out.println("Stronger !");
				break;
			case 108:
				s_iLife++;
				hasEat=true;
				System.out.println("More Life!");
				break;
			case 109:
				m_iBlood++;	
				hasEat=true;
				System.out.println("Healthy !");
				break;
			case 110:
				m_abBombkind[7]+=1;
				hasEat=true;
				System.out.println("Bom kind 1 added !");
				break;
			case 111:
				m_abBombkind[8]+=1;
				System.out.println("Bom kind 2 added !");
				hasEat=true;
				break;				
			case 112:
				m_abBombkind[8]+=2;
				System.out.println("Bom kind 3 added !");
				hasEat=true;
				break;
			case 113:
				m_abBombkind[8]+=3;
				System.out.println("Bom kind 4 added !");
				hasEat=true;
				break;			
		}
		if(hasEat)
		{
		data[iInMapY][iInMapX] = FREE_CELL;
		System.out.println("Get Item !");
		}
	}//end EatItem();
	
	public void Move(int[][] data){  // Override Move of Character
		if(CheckDie())return;
		 EatItem(data); //check eat item
		if (cGame.IsKeyHold(cGame.GK_UP) && (iMove==-1))
			{// up
				//System.out.println("UP!");
				m_iDir=D_UP;				
				if(CheckNextCellFree(data, m_iDir))
				{					
					iMove=D_UP;
					iInMapY-=1;
				}
			}
			else if (cGame.IsKeyHold(cGame.GK_DOWN) && (iMove==-1))
			{//down	
				m_iDir=D_DOWN;				
				if(CheckNextCellFree(data, m_iDir))
				{					
					iMove=D_DOWN;
					iInMapY+=1;
				}
			}	
		else if (cGame.IsKeyHold(cGame.GK_LEFT) && (iMove==-1))
			{//left	
				m_iDir=D_LEFT;				
				if(CheckNextCellFree(data, m_iDir))
				{					
					iMove=D_LEFT;
					iInMapX-=1;
				}			
			}
			else if (cGame.IsKeyHold(cGame.GK_RIGHT) && (iMove==-1))
			{//right
				m_iDir=D_RIGHT;				
				if(CheckNextCellFree(data, m_iDir))
				{					
					iMove=D_RIGHT;
					iInMapX+=1;
				}
			}
		if(iMove!=-1)
		{
			if(m_iDir==D_UP || m_iDir==D_DOWN) m_iCharacterY+= (iMove-2)*iStep;
			else if(m_iDir==D_LEFT || m_iDir==D_RIGHT) m_iCharacterX -= (iMove-1)*iStep;			
					
			if((m_iCharacterX==iInMapX*16) && (m_iCharacterY== iInMapY*16)) iMove=-1;			
			
			//draw sprite
			if(iSpr==7)
					iSpr=0;
					else iSpr++;				
			this.setFrame(m_iDir*8+iSpr);
		}
		// this.setPosition(m_iCharacterX-8, m_iCharacterY-10);	
		//this.setPosition(m_iCharacterX-10, m_iCharacterY-24);
		iDepth= m_iCharacterY;
		
			
	}// end of Move()
	
	
	
	
//draw function		
	public void db(String str)
	{
		System.out.println(str);
	}
	
}
